<?php

include_once '../../__global.php';

class aj_add3rdFollows extends ml_controller{
    
    private $oRedis;
    
    function initParam() {
        
    }
    
    function main() {
    
    
        $uid = $this->__visitor['uid'];            //当前登录用户uid
        
        $oFollow = new ml_model_dbFollow();
        $oFans = new ml_model_dbFans();
        
        
        $oRdsE = new ml_model_rdsExtFollow();
        $arrFollow = $oRdsE->get_extFollow($uid, 0, -1);
        

        // 获取当前登陆者的关注数
        $this->oRedis = new ml_model_rdsCount();
        $followCnt = $this->oRedis->getFollowCnt($uid);
        
        if($followCnt >= ML_FOLLOW_MAXNUM || ($followCnt + count($arrFollow)) >= ML_FOLLOW_MAXNUM) {
            $this->api_output(ML_RCODE_FAIL,array('msg'=>'超过关注上线'),'超过关注上线');
            exit;
        }
        
        $rs = $oFollow->getListByFollowUid($uid,$arrFollow);
        $followed = $oFollow->get_data();
        $followed = Tool_array::format_2d_array($followed , 'follow_uid' , Tool_array::FORMAT_VALUE2VALUE2 ,'uid');
        
        
        
        
        foreach($arrFollow as $k => $v) {
            //    如果关注过  则从数组中移除。
            if($followed[$v] > 0) {
                unset($arrFollow[$k]);
            }else {    //    没有关注的就投 关注队列， 队列里
                $data['uid'] = $uid;
                $data['follow_uid'] = $arrFollow[$k];
                ml_tool_sendMq::add_follow($data);
            }
        }
         
        if(count($arrFollow) > 0 )
        //要判断哪些是已经 关注的
        $rs = $oFollow->addFollows($uid, $arrFollow);

            
        if($rs) { //  成功
            ml_tool_actionlog::add_follow($this->__visitor['uid'] , implode(';' , $arrFollow));
            $oRdsE->delete(ml_model_rdsExtFollow::EXT_FOLLOW.$uid);
            $this->api_output(ML_RCODE_SUCC);
        }else {   //  修改密码失败
            $this->api_output(ML_RCODE_FAIL,array('加关注失败'));
        }
    }
    
    
    
    function checkParam(){
        $this->check_referer();
        
        if(empty($this->__visitor['uid'])){
            $this->api_output(ML_RCODE_NOLOGIN);
        }
    }
}

new aj_add3rdFollows();

